/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package loja.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author eqalmeida
 */
@Entity
@Table(name = "pedidos")
@XmlRootElement
public class Pedido implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "num")
    private Integer num;
    @Basic(optional = false)
    @NotNull
    @Column(name = "data")
    @Temporal(TemporalType.TIMESTAMP)
    private Date data;
    @Basic(optional = false)
    @NotNull
    @Column(name = "status")
    private short status;
    @JoinColumn(name = "cliente_id", referencedColumnName = "id")
    @ManyToOne
    private Cliente clienteId;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "pedido")
    private Collection<ItemPedido> itensCollection;

    public Pedido() {
    }

    public Pedido(Integer num) {
	this.num = num;
    }

    public Pedido(Integer num, Date data, short status) {
	this.num = num;
	this.data = data;
	this.status = status;
    }

    public Integer getNum() {
	return num;
    }

    public void setNum(Integer num) {
	this.num = num;
    }

    public Date getData() {
	return data;
    }

    public void setData(Date data) {
	this.data = data;
    }

    public short getStatus() {
	return status;
    }

    public void setStatus(short status) {
	this.status = status;
    }

    public Cliente getClienteId() {
	return clienteId;
    }

    public void setClienteId(Cliente clienteId) {
	this.clienteId = clienteId;
    }

    @XmlTransient
    public Collection<ItemPedido> getItensCollection() {
	return itensCollection;
    }

    public void setItensCollection(Collection<ItemPedido> itensCollection) {
	this.itensCollection = itensCollection;
    }

    @Override
    public int hashCode() {
	int hash = 0;
	hash += (num != null ? num.hashCode() : 0);
	return hash;
    }

    @Override
    public boolean equals(Object object) {
	// TODO: Warning - this method won't work in the case the id fields are not set
	if (!(object instanceof Pedido)) {
	    return false;
	}
	Pedido other = (Pedido) object;
	if ((this.num == null && other.num != null) || (this.num != null && !this.num.equals(other.num))) {
	    return false;
	}
	return true;
    }

    @Override
    public String toString() {
	return "loja.entity.Pedidos[ num=" + num + " ]";
    }
    
}
